{% extends 'base_main.html' %}
{% block title %}
<title>评论</title>
{% endblock %}
{% block content%}
{{block.super}}
    <div class="col-sm-9 col-sm-offset-3 col-md-10 col-lg-10 col-md-offset-2 main" id="main">
      <form action="/Comment/checkAll" method="post">
        <h1 class="page-header">管理 <span class="badge">{{result.paginator.count}}</span></h1>
        <div class="table-responsive">
          <table class="table table-striped table-hover">
            <thead>
              <tr>
                <th><span class="glyphicon glyphicon-th-large"></span> <span class="visible-lg">选择</span></th>
                <th><span class="glyphicon glyphicon-file"></span> <span class="visible-lg">评论人</span></th>
                <th><span class="glyphicon glyphicon-file"></span> <span class="visible-lg">评论文章</span></th>
                <th><span class="glyphicon glyphicon-file"></span> <span class="visible-lg">摘要</span></th>
                <th><span class="glyphicon glyphicon-time"></span> <span class="visible-lg">日期</span></th>
                <th><span class="glyphicon glyphicon-pencil"></span> <span class="visible-lg">操作</span></th>
              </tr>
            </thead>
            <tbody>
            {% for c in result %}
              <tr>
                <td><input type="checkbox" class="input-control" name="checkbox[]" value="" /></td>
                <td class="article-title">{{c.0}}</td>
                <td class="article-title">{{c.1}}</td>
                <td class="article-title">{{c.2}}</td>
                <td>{{c.3|date:'Y-m-d'}}</td>
                <td><a rel="{{c.4}}" name="delete">删除</a></td>
              </tr>
            {% endfor %}
            </tbody>
          </table>
        </div>
        <footer class="message_footer">
          <nav>
            <div class="btn-toolbar operation" role="toolbar">
              <div class="btn-group" role="group"> <a class="btn btn-default" onClick="select()">全选</a> <a class="btn btn-default" onClick="reverse()">反选</a> <a class="btn btn-default" onClick="noselect()">不选</a> </div>
              <div class="btn-group" role="group">
                <button type="submit" class="btn btn-default" data-toggle="tooltip" data-placement="bottom" title="删除全部选中" name="checkbox_delete">删除</button>
              </div>
            </div>
            <ul class="pagination pagenav">
              <li {% if result.has_previous == False %}class="disabled"{% endif %}>
                <a {% if result.has_previous %}href="{% url 'myblog:comment' %}?page={{result.number|add:'-1'}}" {% else %} href ="javascript:;" {% endif %} aria-label="Previous">
                  <span aria-hidden="true">&laquo;</span>
                </a>
              </li>
              {% for p in result.paginator.page_range %}
              <li {% if p == result.number %}class="active"{% endif %}>
                <a href="{% url 'myblog:comment' %}?page={{p}}">{{forloop.counter}}
                </a>
              </li>
              {% endfor %}
              <li {% if result.has_next == False %}class="disabled"{% endif %}>
                <a {% if result.has_next %}href="{% url 'myblog:comment' %}?page={{result.number|add:'1'}}" {% else %} href ="javascript:;" {% endif %} aria-label="Next">
                  <span aria-hidden="true">&raquo;</span>
                </a>
              </li>
            </ul>
          </nav>
        </footer>
      </form>
    </div>
{% endblock %}
{% block js%}
{{block.super}}
<script src="/static/js/bootstrap.min.js"></script>
<script>
$(function () {
    $("#main table tbody tr td a").click(function () {
        var name = $(this);
        var id = name.attr("rel"); //对应id   
        if (name.attr("name") === "delete") {
            if (window.confirm("此操作不可逆，是否确认？")) {
                $.ajax({
                    type: "POST",
                    url: "/myblog/del_comment/",
                    data: "com_id=" + id,
                    cache: false, //不缓存此页面   
                    success: function (data) {
                        if(data.code == '200'){
                          window.location.reload();
                        }
                    }
                });
            };
        };
    });
});
</script>
{% endblock %}